
-- --------------------------------------------------
-- Entity Designer DDL Script for SQL Server 2005, 2008, and Azure
-- --------------------------------------------------
-- Date Created: 02/05/2013 10:01:20
-- Generated from EDMX file: E:\_TFS\mano_logging_dev\Source\Precio.Logging\Model\Logging.edmx
-- --------------------------------------------------

SET QUOTED_IDENTIFIER OFF;
GO
USE [Logging];
GO
IF SCHEMA_ID(N'Logging') IS NULL EXECUTE(N'CREATE SCHEMA [Logging]');
GO

-- --------------------------------------------------
-- Dropping existing FOREIGN KEY constraints
-- --------------------------------------------------

IF OBJECT_ID(N'[Logging].[FK_LogEntryExtendedProperty]', 'F') IS NOT NULL
    ALTER TABLE [Logging].[ExtendedProperties] DROP CONSTRAINT [FK_LogEntryExtendedProperty];
GO

-- --------------------------------------------------
-- Dropping existing tables
-- --------------------------------------------------

IF OBJECT_ID(N'[Logging].[LogEntries]', 'U') IS NOT NULL
    DROP TABLE [Logging].[LogEntries];
GO
IF OBJECT_ID(N'[Logging].[ExtendedProperties]', 'U') IS NOT NULL
    DROP TABLE [Logging].[ExtendedProperties];
GO
IF OBJECT_ID(N'[Logging].[Continuations]', 'U') IS NOT NULL
    DROP TABLE [Logging].[Continuations];
GO
IF OBJECT_ID(N'[Logging].[Followers]', 'U') IS NOT NULL
    DROP TABLE [Logging].[Followers];
GO

-- --------------------------------------------------
-- Creating all tables
-- --------------------------------------------------

-- Creating table 'LogEntries'
CREATE TABLE [Logging].[LogEntries] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Source] nvarchar(256)  NULL,
    [EventType] nvarchar(50)  NULL,
    [EventId] int  NOT NULL,
    [Category] nvarchar(256)  NULL,
    [Timestamp] datetime  NOT NULL,
    [Message] nvarchar(max)  NULL,
    [Data] nvarchar(max)  NULL,
    [ClientIdentity] nvarchar(256)  NULL,
    [ExecutingIdentity] nvarchar(256)  NULL,
    [TraceSessionId] nvarchar(256)  NULL,
    [ActivityId] nvarchar(128)  NULL,
    [RelatedActivityId] nvarchar(128)  NULL,
    [MachineName] nvarchar(50)  NULL,
    [MethodName] nvarchar(512)  NULL,
    [AppDomainName] nvarchar(256)  NULL,
    [ProcessId] int  NULL,
    [ProcessName] nvarchar(256)  NULL,
    [ThreadId] int  NULL,
    [Area] nvarchar(256)  NULL,
    [OriginalCaller] nvarchar(256)  NULL,
    [DurationMilliseconds] float  NULL,
    [ExtRefId] nvarchar(256)  NULL,
    [ClientVersion] nvarchar(256)  NULL,
    [ClientInfo] nvarchar(512)  NULL,
    [Environment] nvarchar(16)  NULL,
    [Version] nvarchar(32)  NULL,
    [LogEntryId] uniqueidentifier  NULL
);
GO

-- Creating table 'ExtendedProperties'
CREATE TABLE [Logging].[ExtendedProperties] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [Name] nvarchar(250)  NOT NULL,
    [Value] nvarchar(max)  NULL,
    [LogEntryId] int  NOT NULL
);
GO

-- Creating table 'Continuations'
CREATE TABLE [Logging].[Continuations] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [TraceSessionId] nvarchar(250)  NULL,
    [Token] nvarchar(250)  NULL,
    [ExtRefId] nvarchar(250)  NULL,
    [Timestamp] datetime  NULL
);
GO

-- Creating table 'Followers'
CREATE TABLE [Logging].[Followers] (
    [Id] int IDENTITY(1,1) NOT NULL,
    [TraceSessionId] nvarchar(250)  NULL,
    [Token] nvarchar(250)  NULL,
    [ExtRefId] nvarchar(250)  NULL,
    [Timestamp] datetime  NULL
);
GO

-- --------------------------------------------------
-- Creating all PRIMARY KEY constraints
-- --------------------------------------------------

-- Creating primary key on [Id] in table 'LogEntries'
ALTER TABLE [Logging].[LogEntries]
ADD CONSTRAINT [PK_LogEntries]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'ExtendedProperties'
ALTER TABLE [Logging].[ExtendedProperties]
ADD CONSTRAINT [PK_ExtendedProperties]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Continuations'
ALTER TABLE [Logging].[Continuations]
ADD CONSTRAINT [PK_Continuations]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- Creating primary key on [Id] in table 'Followers'
ALTER TABLE [Logging].[Followers]
ADD CONSTRAINT [PK_Followers]
    PRIMARY KEY CLUSTERED ([Id] ASC);
GO

-- --------------------------------------------------
-- Creating all FOREIGN KEY constraints
-- --------------------------------------------------

-- Creating foreign key on [LogEntryId] in table 'ExtendedProperties'
ALTER TABLE [Logging].[ExtendedProperties]
ADD CONSTRAINT [FK_LogEntryExtendedProperty]
    FOREIGN KEY ([LogEntryId])
    REFERENCES [Logging].[LogEntries]
        ([Id])
    ON DELETE NO ACTION ON UPDATE NO ACTION;

-- Creating non-clustered index for FOREIGN KEY 'FK_LogEntryExtendedProperty'
CREATE INDEX [IX_FK_LogEntryExtendedProperty]
ON [Logging].[ExtendedProperties]
    ([LogEntryId]);
GO

-- --------------------------------------------------
-- Script has ended
-- --------------------------------------------------